//#include <stdio.h> //包含在game.h中了，这里不用再包含了
#include "game.h"

void menu(){
    printf("*******************************\n");
    printf("*********** 1.play ************\n");
    printf("*********** 0.exit ************\n");
    printf("*******************************\n");
}

void game(){
    char board[ROW][COL] = {0}; //九宫格棋盘
    char ret = 0;
    //初始化棋盘
    InitBoard(board,ROW,COL);
    //打印棋盘
    DisplayBoard(board,ROW,COL);
    while(1){
        //玩家下棋
        PlayerMove(board,ROW,COL);
        //判断输赢
        ret = IsWin(board,ROW,COL);
        if (ret != 'C'){
            break;
        }
        DisplayBoard(board,ROW,COL);
        //电脑下棋
        ComputerMove(board,ROW,COL);
        DisplayBoard(board,ROW,COL);
        ret = IsWin(board,ROW,COL);
        if (ret != 'C'){
            break;
        }
    }
    if(ret == '*'){
        printf("玩家赢\n");
    }
    else if(ret == '#'){
        printf("电脑赢\n");
    }
    else{
        printf("平局\n");
    }
}

int main(){
    srand((unsigned int) time(NULL));//设置随机数的生成起点
    int input = 0;
    do{
        menu();//打印菜单
        printf("请选择:>");
        scanf("%d",&input);
        switch (input)
        {
        case 1:
            //printf("三子棋\n");
            game();
            break;
        case 0:
            printf("退出\n");
            break; 
        default:
            printf("选择错误\n");
            break;
        }
    }while(input);
    return 0;
}